import com.project.servlet.TestServlet;
import org.apache.catalina.Context;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.Wrapper;
import org.apache.catalina.startup.Tomcat;

public class Main {
    public Main() {
        Tomcat tomcat = new Tomcat();
        //设置tomcat端口
        tomcat.setPort(8088);
        //引导http引擎
        tomcat.getConnector();

        //定义上下文
        Context context = tomcat.addContext("", null);
        //注册servlet，第一个参数为上下文对象，第二个参数为servlet名称，第三个参数为servlet实现类对象
        Wrapper wp = Tomcat.addServlet(context, "test", new TestServlet());
        //容器一启动就初始化
        wp.setLoadOnStartup(1);
        //配置servlet的环境
        wp.addMapping("/abc");
        //
       //http://localhost:8088/abc

        try {
            //启动tomcat
            tomcat.start();
        } catch (LifecycleException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        new Main();
    }
}
